package com.ruoyi.wechat.api;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ConvertUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.wechat.domain.Evaluate;
import com.ruoyi.wechat.domain.WxEvaluate;
import com.ruoyi.wechat.service.IEvaluateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>ClassName : WxEvaluateController</p>
 * <p>Description : </p>
 *
 * @author 孙伟光
 * @version 1.0
 * @date 2024/7/30 15:47
 */
@Api(value = "微信小程序API-营地评价管理", tags = {"微信小程序API-营地评价管理"})
@RestController
@RequestMapping("/wechat/evaluate")
public class WxEvaluateController extends BaseController {

    @Autowired
    private IEvaluateService evaluateService;

    /**
     * 查询营地评价列表
     */
    @ApiOperation(value = "根据营地Id获取该营地下所有的评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "campId", value = "营地Id", required = true, dataType = "String", paramType = "query"),
    })
    @GetMapping("/list")
    public AjaxResult list(WxEvaluate wxEvaluate)
    {
        Evaluate evaluate = ConvertUtils.sourceToTarget(wxEvaluate, Evaluate.class);
        List<Evaluate> list = evaluateService.selectEvaluateList(evaluate);
        return success(list);
    }

    /**
     * 获取营地评价详细信息
     */
    @ApiOperation(value = "根据评论Id获取该评论的所有信息")
    @GetMapping(value = "/{evaluateId}")
    public AjaxResult getInfo(@PathVariable("evaluateId") String evaluateId)
    {
        return success(evaluateService.selectEvaluateByEvaluateId(evaluateId));
    }

    /**
     * 新增营地评价
     */
    @ApiOperation(value = "添加评论")
    @Log(title = "微信接口-营地评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxEvaluate wxEvaluate)
    {
        Evaluate evaluate = ConvertUtils.sourceToTarget(wxEvaluate, Evaluate.class);
        return toAjax(evaluateService.insertEvaluate(evaluate));
    }

    /**
     * 删除营地评价
     */
    @ApiOperation(value = "根据评论Id删除数据")
    @Log(title = "微信接口-营地评价", businessType = BusinessType.DELETE)
    @DeleteMapping("/{evaluateId}")
    public AjaxResult remove(@PathVariable String evaluateId)
    {
        return toAjax(evaluateService.deleteEvaluateByEvaluateId(evaluateId));
    }
}
